package org.budo.validation.exception;

import javax.validation.constraints.Size;

/**
 * @author lmw
 */
public class BudoSizeValidationException extends AbstractBudoValidationException {
    private static final long serialVersionUID = 4969260450165845737L;

    private static final String MESSAGE_DEFAULT = "{javax.validation.constraints.Size.message}";

    public BudoSizeValidationException() {}

    public BudoSizeValidationException(Integer parameterIndex, String parameterName, Size annotation, Object parameterValue) {
        super(parameterIndex, parameterName, annotation, parameterValue, validationMessage(annotation.message(), MESSAGE_DEFAULT));
    }

    @Override
    protected String buildMessage() {
        Size size = (Size) this.getAnnotation();
        return "parameter[" + this.getParameterIndex() + "] " + this.getParameterName() + " size " + this.getParameterValue()//
                + " is not in [" + size.min() + ", " + size.max() + "]";
    }
}